package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import session.SessionVariables;
import vo.CarritoVO;
import facade.BD;

/**
 * Servlet implementation class ConfirmarCarrito
 */
@WebServlet("/ConfirmarCarrito")
public class ConfirmarCarrito extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConfirmarCarrito() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		BD bd = BD.getInstance();
		
		bd.confirmarCarrito();
		
		CarritoVO carrito = bd.getCarrito();
		
		SessionVariables.getInstance().setCarrito(carrito);
		
		String jspPage = "/BusquedaArticulos.jsp";
		
		dispatch(jspPage, request, response);
		}

	protected void dispatch(String jsp, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			if (jsp != null)
			{
			    RequestDispatcher rd = request.getRequestDispatcher(jsp);
			    rd.forward(request, response);
			}
		}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
